/*****************************************
 * AD9910模块引脚说明
 * D0 ~ D15		I
 * PC					O			PDCLK, 并行数据时钟
 * TE					I			TxENABLE, 发送使能
 * 
 * MRT				I			MASTER_RESET
 * CSN				I			I/O_RESET
 * SCK				O
 * SDI				IO
 * IUP				IO		I/O_UPDATE
 * DRH				I			DRHOLD
 * DRC				I			DRCTL
 * DRO				O			DROVER
 * OSK				I			输出振幅键控
 * PF0 ~ PF2	I			PROFILE
 * SYN				O			SYNC_CLK
 * RSO				O			RAM_SWP_OVR
 ******************************************/
#include "Drv_AD9910.h"
#include "bitBand.h"


// addr				Profile 通道的选择        (0--7)总共有8个Profile
// Freq				单频中的频率的设置        (1Hz--450MHz)
// Amp				单频中的幅度设置				  (0x0000--0x3FFF)   
// Pha				单频中的相位设置          (0--360°)

// AD9910 Mode Setting
#define AD9910_SINGLE_MODE    1 // 单频调制
#define AD9910_OSK_MODE       0 // 输出移位键控(OSK)
#define AD9910_DRG_MODE       0 // 数字斜波调制(DRG)
#define AD9910_RAM_MODE       1 // RAM调制 TODO, 仅实现波形输出
#define AD9910_PARALLEL_MODE  0 // 并行数据端口调制

// AD9910 Pin Setting
#define USING_SERIAL_PORT_MODE 1
#if USING_SERIAL_PORT_MODE
#define AD9910_MRT_SET(x) HAL_GPIO_WritePin(AD9910_MRT_GPIO_Port, AD9910_MRT_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_CSN_SET(x) HAL_GPIO_WritePin(AD9910_CSN_GPIO_Port, AD9910_CSN_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_SCK_SET(x) HAL_GPIO_WritePin(AD9910_SCK_GPIO_Port, AD9910_SCK_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_SDI_SET(x) HAL_GPIO_WritePin(AD9910_SDI_GPIO_Port, AD9910_SDI_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_IUP_SET(x) HAL_GPIO_WritePin(AD9910_IUP_GPIO_Port, AD9910_IUP_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
// #define AD9910_DRH_SET(x) HAL_GPIO_WritePin(AD9910_DRH_GPIO_Port, AD9910_DRH_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
// #define AD9910_DRC_SET(x) HAL_GPIO_WritePin(AD9910_DRC_GPIO_Port, AD9910_DRC_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_PF0_SET(x) HAL_GPIO_WritePin(AD9910_PF0_GPIO_Port, AD9910_PF0_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_PF1_SET(x) HAL_GPIO_WritePin(AD9910_PF1_GPIO_Port, AD9910_PF1_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_PF2_SET(x) HAL_GPIO_WritePin(AD9910_PF2_GPIO_Port, AD9910_PF2_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
// #define AD9910_OSK_SET(x) HAL_GPIO_WritePin(AD9910_OSK_GPIO_Port, AD9910_OSK_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)

// #define AD9910_MRT_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_CSN_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_SCK_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_SDI_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_IUP_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_DRH_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_DRC_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_PF0_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_PF1_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_PF2_SET(x) { PAout(0) = x; }while(0)
// #define AD9910_OSK_SET(x) { PAout(0) = x; }while(0)
#endif

#define USING_PARALLEL_PORT_MODE 0
#if USING_PARALLEL_PORT_MODE
#define AD9910_PC_SET(x)  HAL_GPIO_WritePin(AD9910_PC_GPIO_Port,  AD9910_PC_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_TE_SET(x)  HAL_GPIO_WritePin(AD9910_TE_GPIO_Port,  AD9910_TE_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_F0_SET(x)  HAL_GPIO_WritePin(AD9910_F0_GPIO_Port,  AD9910_F0_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_F1_SET(x)  HAL_GPIO_WritePin(AD9910_F1_GPIO_Port,  AD9910_F1_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D0_SET(x)  HAL_GPIO_WritePin(AD9910_D0_GPIO_Port,  AD9910_D0_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D1_SET(x)  HAL_GPIO_WritePin(AD9910_D1_GPIO_Port,  AD9910_D1_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D2_SET(x)  HAL_GPIO_WritePin(AD9910_D2_GPIO_Port,  AD9910_D2_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D3_SET(x)  HAL_GPIO_WritePin(AD9910_D3_GPIO_Port,  AD9910_D3_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D4_SET(x)  HAL_GPIO_WritePin(AD9910_D4_GPIO_Port,  AD9910_D4_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D5_SET(x)  HAL_GPIO_WritePin(AD9910_D5_GPIO_Port,  AD9910_D5_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D6_SET(x)  HAL_GPIO_WritePin(AD9910_D6_GPIO_Port,  AD9910_D6_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D7_SET(x)  HAL_GPIO_WritePin(AD9910_D7_GPIO_Port,  AD9910_D7_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D8_SET(x)  HAL_GPIO_WritePin(AD9910_D8_GPIO_Port,  AD9910_D8_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D9_SET(x)  HAL_GPIO_WritePin(AD9910_D9_GPIO_Port,  AD9910_D9_Pin,  (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D10_SET(x) HAL_GPIO_WritePin(AD9910_D10_GPIO_Port, AD9910_D10_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D11_SET(x) HAL_GPIO_WritePin(AD9910_D11_GPIO_Port, AD9910_D11_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D12_SET(x) HAL_GPIO_WritePin(AD9910_D12_GPIO_Port, AD9910_D12_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D13_SET(x) HAL_GPIO_WritePin(AD9910_D13_GPIO_Port, AD9910_D13_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D14_SET(x) HAL_GPIO_WritePin(AD9910_D14_GPIO_Port, AD9910_D14_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)
#define AD9910_D15_SET(x) HAL_GPIO_WritePin(AD9910_D15_GPIO_Port, AD9910_D15_Pin, (x) ?GPIO_PIN_SET :GPIO_PIN_RESET)

// #define AD9910_PC_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_TE_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_F0_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_F1_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D0_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D1_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D2_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D3_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D4_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D5_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D6_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D7_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D8_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D9_SET(x)  { PAout(0) = (x); }while(0)
// #define AD9910_D10_SET(x) { PAout(0) = (x); }while(0)
// #define AD9910_D11_SET(x) { PAout(0) = (x); }while(0)
// #define AD9910_D12_SET(x) { PAout(0) = (x); }while(0)
// #define AD9910_D13_SET(x) { PAout(0) = (x); }while(0)
// #define AD9910_D14_SET(x) { PAout(0) = (x); }while(0)
// #define AD9910_D15_SET(x) { PAout(0) = (x); }while(0)
#endif


void Delay(uint32_t x)
{
  uint32_t delayCNT;
  for(delayCNT=0; delayCNT<(x); ++delayCNT);
}

void Write_8bits(uint8_t data)
{
  uint32_t i, com;

  com = 0x80;
  AD9910_SCK_SET(0);
  for(i=0; i<8; ++i)
  {
    AD9910_SDI_SET( (data & com) );
    AD9910_SCK_SET(1);
    com >>= 1;
    AD9910_SCK_SET(0);
  }
}

void Write_32bits(uint32_t data)
{
  uint32_t i;
  uint32_t com;

  com = 0x80000000;
  AD9910_SCK_SET(0);
  for(i=0; i<32; ++i)
  {
    AD9910_SDI_SET( (data & com) );
    AD9910_SCK_SET(1);
    com >>= 1;
    AD9910_SCK_SET(0);
  }
}

void AD9910_Init()
{
  uint32_t i;
  // CFR3控制功能寄存器3   时钟倍频40倍  基础时钟25M   最终时钟=1 000 000 000 Hz
  uint8_t CFR3[]={0x05,0x0F,0x41,0x50};
  // 辅助DAC输出  默认0x7f
  uint8_t Assist_DAC[]={0x00,0x00,0x00,0x7F};

  // 复位
  AD9910_MRT_SET(1);
  AD9910_MRT_SET(0);
  // 片选
  AD9910_CSN_SET(0);
  // 选择0x02地址 CFR3寄存器写入数据 CFR3是控制时钟倍频之类的寄存器
  Write_8bits(0x02);
  for(i=0; i<4; ++i)
  {
    Write_8bits(CFR3[i]);
  }
  // disable select
  AD9910_CSN_SET(1);
  Delay(10);

  AD9910_CSN_SET(0); // 片选
  // // 选择0x03地址 辅助DAC控制写入数据 控制DAC输出的幅度
  Write_8bits(0x03);
  for(i=0; i<4; ++i)
  {
    Write_8bits(Assist_DAC[i]);
  }
  AD9910_CSN_SET(1);
  Delay(10);
  
  // 更新输出
  AD9910_IUP_SET(0);
  Delay(10);
  AD9910_IUP_SET(1);
  Delay(10);
  AD9910_IUP_SET(0);
  Delay(10);
}

void Set_Profile(uint8_t num)
{
	switch(num)
	{
    // Profile 0     引脚PF2~PF0——000
		case 0 :{
							AD9910_PF2_SET(0);
							AD9910_PF1_SET(0);
							AD9910_PF0_SET(0);
						}break;
    // Profile 1     引脚PF2~PF0——001
		case 1 :{
							AD9910_PF2_SET(0);
							AD9910_PF1_SET(0);
							AD9910_PF0_SET(1);
						}break;
    // Profile 2     引脚PF2~PF0——010
		case 2 :{
							AD9910_PF2_SET(0);
							AD9910_PF1_SET(1);
							AD9910_PF0_SET(0);
						}break;
    // Profile 3     引脚PF2~PF0——011
		case 3 :{
							AD9910_PF2_SET(0);
							AD9910_PF1_SET(1);
							AD9910_PF0_SET(1);
						}break;
    // Profile 4     引脚PF2~PF0——100
		case 4 :{
							AD9910_PF2_SET(1);
							AD9910_PF1_SET(0);
							AD9910_PF0_SET(0);
						}break;
    // Profile 5     引脚PF2~PF0——101
		case 5 :{
							AD9910_PF2_SET(1);
							AD9910_PF1_SET(0);
							AD9910_PF0_SET(1);
						}break;
    // Profile 6     引脚PF2~PF0——110
		case 6 :{
							AD9910_PF2_SET(1);
							AD9910_PF1_SET(1);
							AD9910_PF0_SET(0);
						}break;
    // Profile 7     引脚PF2~PF0——111
		case 7 :{
							AD9910_PF2_SET(1);
							AD9910_PF1_SET(1);
							AD9910_PF0_SET(1);
						}break;
		default:break;
	}

  // 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

#if AD9910_SINGLE_MODE

void AD9910_Singal_Profile_Init()
{
  uint32_t i;
  // 开启AD9910反Sinc滤波器
  uint8_t CFR1[]={0x00,0x40,0x00,0x00};
  // 使能单频Profiles调制幅度 (SYNC_CLK使能	PDCLK使能		同步时序验证禁用——这些是默认的)
  uint8_t CFR2[]={0x01,0x40,0x08,0x20};

  // 将单频模式的CFR1[]写入CFR1寄存器地址
  AD9910_CSN_SET(0);
  Write_8bits(0x00);
  for(i=0; i<4; ++i)
    Write_8bits(CFR1[i]);
  AD9910_CSN_SET(1);

  Delay(10);

  // 将单频模式的CFR2[]写入CFR2寄存器地址
  AD9910_CSN_SET(0);
  Write_8bits(0x01);
  for(i=0; i<4; ++i)
    Write_8bits(CFR2[i]);
  AD9910_CSN_SET(1);

  Delay(10);

  // 更新输出
  AD9910_IUP_SET(0);
  Delay(10);
  AD9910_IUP_SET(1);
  Delay(10);
  AD9910_IUP_SET(0);
  Delay(10);
}

void AD9910_Singal_Profile_Set(uint32_t addr, uint32_t freq, uint32_t pha, uint32_t amp)
{
  uint32_t i;
  uint8_t  tmp_addr;
  uint8_t  Profile_All[8];

  // 频率对应上频率的FTW		4.294967296=(2^32)/1000000000		
  // 设置的范围是(1Hz~450MHz)
  uint32_t tmp_freq = (uint32_t)freq*4.294967296;
  // 相位对应上相位的POW		182.044444444=2^16/360
  // 设置的范围是(0~360°)
  uint32_t tmp_pha  = (uint16_t)pha*182.044444444;
  // 因为幅度无法准确的对应上,所以没有转换
  // 设置的范围是(0x0000~0x3FFF)
  uint32_t tmp_amp = amp;

  switch(addr)  // 选择要写入的通道（通道0~7）
  {
    case 0 :	tmp_addr=0x0e;break;
    case 1 :	tmp_addr=0x0f;break;
    case 2 :	tmp_addr=0x10;break;
    case 3 :	tmp_addr=0x11;break;
    case 4 :	tmp_addr=0x12;break;
    case 5 :	tmp_addr=0x13;break;
    case 6 :	tmp_addr=0x14;break;
    case 7 :	tmp_addr=0x15;break;
    default:break;
  }

  // 将频率幅度相位的值存入暂存地址——Profile_All
  Profile_All[7]=(uint8_t)tmp_freq;  // 将频率幅度相位的值存入暂存地址——Profile_All
  Profile_All[6]=(uint8_t)(tmp_freq>>8);
  Profile_All[5]=(uint8_t)(tmp_freq>>16);
  Profile_All[4]=(uint8_t)(tmp_freq>>24);
  Profile_All[3]=(uint8_t)tmp_pha;
  Profile_All[2]=(uint8_t)(tmp_pha>>8);
  Profile_All[1]=(uint8_t)tmp_amp;
  Profile_All[0]=(uint8_t)(tmp_amp>>8);

  AD9910_CSN_SET(0);
  Write_8bits(tmp_addr);
  for(i=0; i<8; ++i)
  {
    Write_8bits(Profile_All[i]);
  }
  AD9910_CSN_SET(1);
  Delay(10);

  AD9910_IUP_SET(0);
  Delay(10);
  AD9910_IUP_SET(1);
  Delay(10);
  AD9910_IUP_SET(0);
  Delay(10);
}

#endif

#if AD9910_OSK_MODE

void AD9910_Osk_Init(void)
{
	uint8_t CFR1[]={0x00,0x40,0x03,0x00};  // 	反Sinc滤波使能，OSK使能，选择自动OSK
	uint8_t CFR2[]={0x00,0x40,0x08,0x20};  // （SYNC_CLK使能	PDCLK使能		同步时序验证禁用）默认值 
	
	int i;
	
  // 将OSK模式的CFR1[]写入CFR1寄存器地址
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 将OSK模式的CFR2[]写入CFR2寄存器地址
	AD9910_CSN_SET(0);
	Write_8bits(0x01);
	for(i=0; i<4; i++)
		Write_8bits(CFR2[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

void AD9910_Osk_Set(void)
{
	uint8_t ASF[]={0x0f,0xff,0xff,0xf0};  // 振幅比例因子的设置
	int i;

  // 将OSK模式的振幅比例因子写入振幅比例因子寄存器地址
	AD9910_CSN_SET(0);												
	Write_8bits(0x09);
	for(i=0; i<4; i++)
		Write_8bits(ASF[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

#endif

#if AD9910_DRG_MODE

void AD9910_DRG_Fre_Init(void)
{
	uint8_t CFR1[]={0x00,0x40,0x00,0x00}; // 使能AD9910反Sinc滤波                             				
	uint8_t CFR2[]={0x00,0x48,0x08,0x20}; // SYNC_CLK使能，数字斜坡使能	  CFR2[21:20]= 00   选择控制参数为频率
	int i;
	
  // 将CFR1写入其地址0x00
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
	// 将CFR2写入其地址0x01
	AD9910_CSN_SET(0);
	Write_8bits(0x01);
	for(i=0; i<4; i++)
		Write_8bits(CFR2[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
	// 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

void AD9910_DRG_Freq_set(uint32_t upper_limit , uint32_t lower_limit ,uint32_t dec_step , uint32_t inc_step , uint16_t neg_rate ,uint16_t pos_rate)
{
	uint32_t upper_temp , lower_temp ,dec_temp, inc_temp;
	uint16_t neg_rate_temp , pos_rate_temp;
	int i;

	upper_temp			=	(uint32_t)upper_limit*4.294967296; // 频率字转换		4.294967296=(2^32)/1000000000
	lower_temp			=	(uint32_t)lower_limit*4.294967296;
	dec_temp    		=	(uint32_t)  dec_step*4.294967296;
	inc_temp  	  	=	(uint32_t)  inc_step*4.294967296;
	neg_rate_temp		=  			neg_rate; // 时间
	pos_rate_temp		=  			pos_rate;
	
  //将上限下限频率、频率加减步进、频率加减速率写入数组，后写入相应的寄存器
	DRL[7]=(uint8_t) lower_temp;
	DRL[6]=(uint8_t)(lower_temp>>8);
	DRL[5]=(uint8_t)(lower_temp>>16);
	DRL[4]=(uint8_t)(lower_temp>>24);
	DRL[3]=(uint8_t) upper_temp;
	DRL[2]=(uint8_t)(upper_temp>>8);
	DRL[1]=(uint8_t)(upper_temp>>16);
	DRL[0]=(uint8_t)(upper_temp>>24);
	
	DRS[7]=(uint8_t) inc_temp;
	DRS[6]=(uint8_t)(inc_temp>>8);
	DRS[5]=(uint8_t)(inc_temp>>16);
	DRS[4]=(uint8_t)(inc_temp>>24);
	DRS[3]=(uint8_t) dec_temp;
	DRS[2]=(uint8_t)(dec_temp>>8);
	DRS[1]=(uint8_t)(dec_temp>>16);
	DRS[0]=(uint8_t)(dec_temp>>24);
	
	DRR[3]=(uint8_t) pos_rate_temp;
	DRR[2]=(uint8_t)(pos_rate_temp>>8);
	DRR[1]=(uint8_t) neg_rate_temp;
	DRR[0]=(uint8_t)(neg_rate_temp>>8);
	
  // 将数字斜坡限值存入 0x0B
	AD9910_CSN_SET(0);												
	Write_8bits(0x0B);
	for(i=0; i<8; i++)
		Write_8bits(DRL[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 将数字斜坡步长存入 0x0C
	AD9910_CSN_SET(0);												
	Write_8bits(0x0C);
	for(i=0; i<8; i++)
		Write_8bits(DRS[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 将数字斜坡速率存入 0x0D
	AD9910_CSN_SET(0);												
	Write_8bits(0x0D);
	for(i=0; i<4; i++)
		Write_8bits(DRR[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);	
}

void AD9910_DRG_AMP_Init(void)
{
	uint8_t CFR1[]={0x00,0x40,0x00,0x00}; // 使能AD9910反Sinc滤波                             																			                   				
	uint8_t CFR2[]={0x01,0x69,0x08,0x20}; // SYNC_CLK使能，数字斜坡使能	  CFR2[21:20]= 10   选择控制参数为幅度 	
	int i;
	
  // 将CFR1写入其地址0x00
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 将CFR2写入其地址0x01
	AD9910_CSN_SET(0);
	Write_8bits(0x01);																												
	for(i=0; i<4; i++)
		Write_8bits(CFR2[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
	// 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

void AD9910_DRG_Amp_Set( uint32_t upper_limit , uint32_t lower_limit ,uint32_t dec_step , uint32_t inc_step , uint16_t neg_rate ,uint16_t pos_rate)
{
int i;
uint32_t upper_temp , lower_temp ,dec_temp, inc_temp;
uint16_t neg_rate_temp , pos_rate_temp;
	
	upper_temp			=			upper_limit ;		
	lower_temp			=			lower_limit;
	dec_temp    		=			dec_step;
	inc_temp    		=			inc_step;
	neg_rate_temp		=  		neg_rate;	// 时间
	pos_rate_temp		=  		pos_rate;
	
  //将上限下限幅度、幅度加减步进、幅度加减速率写入数组，后写入相应的寄存器
	DRL[7]=0;
	DRL[6]=0;
	DRL[5]=(uint8_t)(lower_temp<<2);
	DRL[4]=(uint8_t)(lower_temp>>6);
	DRL[3]=0;
	DRL[2]=0;
	DRL[1]=(upper_temp<<2);
	DRL[0]=(upper_temp>>6);
	
	DRS[7]=0;
	DRS[6]=0;
	DRS[5]=(uint8_t)(inc_temp<<2);
	DRS[4]=(uint8_t)(inc_temp>>6);
	DRS[3]=0;
	DRS[2]=0;
	DRS[1]=(uint8_t)(dec_temp<<2);
	DRS[0]=(uint8_t)(dec_temp>>6);

	
	DRR[3]=(uint8_t) pos_rate_temp;
	DRR[2]=(uint8_t)(pos_rate_temp>>8);
	DRR[1]=(uint8_t) neg_rate_temp;
	DRR[0]=(uint8_t)(neg_rate_temp>>8);
	
  // 将DRL(数字斜坡限值)写入 0x0B
	AD9910_CSN_SET(0);												
	Write_8bits(0x0B);
	for(i=0; i<8; i++)
		Write_8bits(DRL[i]);
	AD9910_CSN_SET(1);	

	Delay (10);
	
  // 将DRS(数字斜坡步长)写入 0x0C
	AD9910_CSN_SET(0);												
	Write_8bits(0x0C);
	for(i=0; i<8; i++)
		Write_8bits(DRS[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 将DRR(数字斜坡速率)写入 0x0D
	AD9910_CSN_SET(0);												
	Write_8bits(0x0D);
	for(i=0; i<4; i++)
		Write_8bits(DRR[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

void AD9910_DRG_Pha_Init(void)
{
	uint8_t CFR1[]={0x00,0x40,0x00,0x00}; // 使能AD9910反Sinc滤波                             				
	uint8_t CFR2[]={0x01,0x58,0x08,0x20}; // SYNC_CLK使能，数字斜坡使能	  CFR2[21:20]= 01   选择控制参数为相位
	int i;
	
  // 将CFR1写入其地址0x00
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
	// 将CFR2写入其地址0x01
	AD9910_CSN_SET(0);
	Write_8bits(0x01);
	for(i=0; i<4; i++)
		Write_8bits(CFR2[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
	// 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

void AD9910_DRG_Pha_Set( uint32_t upper_limit , uint32_t lower_limit ,uint32_t dec_step , uint32_t inc_step , uint16_t neg_rate ,uint16_t pos_rate)
{
	int i;
	uint32_t upper_temp , lower_temp ,dec_temp, inc_temp;               
	uint16_t neg_rate_temp , pos_rate_temp;
	
  // 182.044=2^16/360  根据芯片手册的公式
	upper_temp			=			(uint32_t)upper_limit*182.04;
	lower_temp			=			(uint32_t)lower_limit*182.04;
	dec_temp  	  	=			(uint32_t)dec_step*182.04;
	inc_temp    		=			(uint32_t)inc_step*182.04;
	
	upper_temp=upper_temp<<16;
	lower_temp=lower_temp<<16;
	dec_temp=dec_temp<<16;
	inc_temp=inc_temp<<16;
	neg_rate_temp		=  		neg_rate; // 时间
	pos_rate_temp		=  		pos_rate;
	
  // 将上限下限幅度、幅度加减步进、幅度加减速率写入数组，后写入相应的寄存器
	DRL[7]=(uint8_t) lower_temp;
	DRL[6]=(uint8_t)(lower_temp>>8);
	DRL[3]=(uint8_t) upper_temp;
	DRL[2]=(uint8_t)(upper_temp>>8);
	DRS[7]=(uint8_t) inc_temp;
	DRS[6]=(uint8_t)(inc_temp>>8);
	DRS[3]=(uint8_t) dec_temp;
	DRS[2]=(uint8_t)(dec_temp>>8);
	DRR[3]=(uint8_t) pos_rate_temp;
	DRR[2]=(uint8_t)(pos_rate_temp>>8);
	DRR[1]=(uint8_t) neg_rate_temp;
	DRR[0]=(uint8_t)(neg_rate_temp>>8);
	
  // 将DRL(数字斜坡限值)写入 0x0B
	AD9910_CSN_SET(0);												
	Write_8bits(0x0B);
	for(i=0; i<8; i++)
		Write_8bits(DRL[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 将DRS(数字斜坡步长)写入 0x0C
	AD9910_CSN_SET(0);												
	Write_8bits(0x0C);
	for(i=0; i<8; i++)
		Write_8bits(DRS[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 将DRR(数字斜坡速率)写入 0x0D
	AD9910_CSN_SET(0);												
	Write_8bits(0x0D);
	for(i=0; i<4; i++)
		Write_8bits(DRR[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
  // 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

#endif

#if AD9910_RAM_MODE

//---------------------------------------------------------------------------------------------------------------------------------
// 说明：AD9910 RAM 模式 1024*32位数据数组（这个数组的值自己可以定义，这边我设置了0~23 24~273 274~523 524~773 774~1023 共用到了5个Profile）
//																				（数组的地址1023~0，反过来的，因为是串行写入的）
//																				（起始地址是最后一个，终止地址是第一个）
//这是给幅度用的RAM表（熟悉可自己设计, 以下幅度值是大约理论值）
uint32_t RAM_AMP[]=
{
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,   
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,     //744mv
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,        
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,0x7fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,    	//372mv
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,     //186mv
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,      
	0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,0x3fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,    	//93mv
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,     
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,0x1fff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,
	0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,0xffff0000,       //744mv
	0xffff0000,0xffff0000,0xffff0000,0xffff0000
};

//---------------------------------------------------------------------------------------------------------------------------------
// 说明：这是三角波的RAM值
//																				（数组的地址1023~0，反过来的，因为是串行写入的）
//																				（起始地址是最后一个，终止地址是第一个）
uint32_t RAM_AMP_TRIG_WAVE[]=																																														
{
	255,510,765,1020,1275,1530,1785,2040,2295,2550,2805,3060,3315,3570,3825,4080,4335,4590,4845,5100,5355,5610,5865,6120,6375,
	6630,6885,7140,7395,7650,7905,8160,8415,8670,8925,9180,9435,9690,9945,10200,10455,10710,10965,11220,11475,11730,11985,12240,
	12495,12750,13005,13260,13515,13770,14025,14280,14535,14790,15045,15300,15555,15810,16065,16320,16575,16830,17085,17340,
	17595,17850,18105,18360,18615,18870,19125,19380,19635,19890,20145,20400,20655,20910,21165,21420,21675,21930,22185,22440,
	22695,22950,23205,23460,23715,23970,24225,24480,24735,24990,25245,25500,25755,26010,26265,26520,26775,27030,27285,27540,
	27795,28050,28305,28560,28815,29070,29325,29580,29835,30090,30345,30600,30855,31110,31365,31620,31875,32130,32385,32640,
	32895,33150,33405,33660,33915,34170,34425,34680,34935,35190,35445,35700,35955,36210,36465,36720,36975,37230,37485,37740,
	37995,38250,38505,38760,39015,39270,39525,39780,40035,40290,40545,40800,41055,41310,41565,41820,42075,42330,42585,42840,
	43095,43350,43605,43860,44115,44370,44625,44880,45135,45390,45645,45900,46155,46410,46665,46920,47175,47430,47685,47940,
	48195,48450,48705,48960,49215,49470,49725,49980,50235,50490,50745,51000,51255,51510,51765,52020,52275,52530,52785,53040,
	53295,53550,53805,54060,54315,54570,54825,55080,55335,55590,55845,56100,56355,56610,56865,57120,57375,57630,57885,58140,
	58395,58650,58905,59160,59415,59670,59925,60180,60435,60690,60945,61200,61455,61710,61965,62220,62475,62730,62985,63240,
	63495,63750,64005,64260,64515,64770,65025,65280,65532,65025,64770,64515,64260,64005,63750,63495,63240,62985,62730,62475,
	62220,61965,61710,61455,61200,60945,60690,60435,60180,59925,59670,59415,59160,58905,58650,58395,58140,57885,57630,57375,
	57120,56865,56610,56355,56100,55845,55590,55335,55080,54825,54570,54315,54060,53805,53550,53295,53040,52785,52530,52275,
	52020,51765,51510,51255,51000,50745,50490,50235,49980,49725,49470,49215,48960,48705,48450,48195,47940,47685,47430,47175,
	46920,46665,46410,46155,45900,45645,45390,45135,44880,44625,44370,44115,43860,43605,43350,43095,42840,42585,42330,42075,
	41820,41565,41310,41055,40800,40545,40290,40035,39780,39525,39270,39015,38760,38505,38250,37995,37740,37485,37230,36975,
	36720,36465,36210,35955,35700,35445,35190,34935,34680,34425,34170,33915,33660,33405,33150,32895,32640,32385,32130,31875,
	31620,31365,31110,30855,30600,30345,30090,29835,29580,29325,29070,28815,28560,28305,28050,27795,27540,27285,27030,26775,
	26520,26265,26010,25755,25500,25245,24990,24735,24480,24225,23970,23715,23460,23205,22950,22695,22440,22185,21930,21675,
	21420,21165,20910,20655,20400,20145,19890,19635,19380,19125,18870,18615,18360,18105,17850,17595,17340,17085,16830,16575,
	16320,16065,15810,15555,15300,15045,14790,14535,14280,14025,13770,13515,13260,13005,12750,12495,12240,11985,11730,11475,
	11220,10965,10710,10455,10200,9945,9690,9435,9180,8925,8670,8415,8160,7905,7650,7395,7140,6885,6630,6375,6120,5865,5610,
	5355,5100,4845,4590,4335,4080,3825,3570,3315,3060,2805,2550,2295,2040,1785,1530,1275,1020,765,510,255,
	
	2147418112,2147418367,2147418622,2147418877,2147419132,2147419387,2147419642,2147419897,2147420152,2147420407,2147420662,
	2147420917,2147421172,2147421427,2147421682,2147421937,2147422192,2147422447,2147422702,2147422957,2147423212,2147423467,
	2147423722,2147423977,2147424232,2147424487,2147424742,2147424997,2147425252,2147425507,2147425762,2147426017,2147426272,
	2147426527,2147426782,2147427037,2147427292,2147427547,2147427802,2147428057,2147428312,2147428567,2147428822,2147429077,
	2147429332,2147429587,2147429842,2147430097,2147430352,2147430607,2147430862,2147431117,2147431372,2147431627,2147431882,
	2147432137,2147432392,2147432647,2147432902,2147433157,2147433412,2147433667,2147433922,2147434177,2147434432,2147434687,
	2147434942,2147435197,2147435452,2147435707,2147435962,2147436217,2147436472,2147436727,2147436982,2147437237,2147437492,
	2147437747,2147438002,2147438257,2147438512,2147438767,2147439022,2147439277,2147439532,2147439787,2147440042,2147440297,
	2147440552,2147440807,2147441062,2147441317,2147441572,2147441827,2147442082,2147442337,2147442592,2147442847,2147443102,
	2147443357,2147443612,2147443867,2147444122,2147444377,2147444632,2147444887,2147445142,2147445397,2147445652,2147445907,
	2147446162,2147446417,2147446672,2147446927,2147447182,2147447437,2147447692,2147447947,2147448202,2147448457,2147448712,
	2147448967,2147449222,2147449477,2147449732,2147449987,2147450242,2147450497,2147450752,2147451007,2147451262,2147451517,
	2147451772,2147452027,2147452282,2147452537,2147452792,2147453047,2147453302,2147453557,2147453812,2147454067,2147454322,
	2147454577,2147454832,2147455087,2147455342,2147455597,2147455852,2147456107,2147456362,2147456617,2147456872,2147457127,
	2147457382,2147457637,2147457892,2147458147,2147458402,2147458657,2147458912,2147459167,2147459422,2147459677,2147459932,
	2147460187,2147460442,2147460697,2147460952,2147461207,2147461462,2147461717,2147461972,2147462227,2147462482,2147462737,
	2147462992,2147463247,2147463502,2147463757,2147464012,2147464267,2147464522,2147464777,2147465032,2147465287,2147465542,
	2147465797,2147466052,2147466307,2147466562,2147466817,2147467072,2147467327,2147467582,2147467837,2147468092,2147468347,
	2147468602,2147468857,2147469112,2147469367,2147469622,2147469877,2147470132,2147470387,2147470642,2147470897,2147471152,
	2147471407,2147471662,2147471917,2147472172,2147472427,2147472682,2147472937,2147473192,2147473447,2147473702,2147473957,
	2147474212,2147474467,2147474722,2147474977,2147475232,2147475487,2147475742,2147475997,2147476252,2147476507,2147476762,
	2147477017,2147477272,2147477527,2147477782,2147478037,2147478292,2147478547,2147478802,2147479057,2147479312,2147479567,
	2147479822,2147480077,2147480332,2147480587,2147480842,2147481097,2147481352,2147481607,2147481862,2147482117,2147482372,
	2147482627,2147482882,2147483137,2147483392,2147483137,2147482882,2147482627,2147482372,2147482117,2147481862,2147481607,
	2147481352,2147481097,2147480842,2147480587,2147480332,2147480077,2147479822,2147479567,2147479312,2147479057,2147478802,
	2147478547,2147478292,2147478037,2147477782,2147477527,2147477272,2147477017,2147476762,2147476507,2147476252,2147475997,
	2147475742,2147475487,2147475232,2147474977,2147474722,2147474467,2147474212,2147473957,2147473702,2147473447,2147473192,
	2147472937,2147472682,2147472427,2147472172,2147471917,2147471662,2147471407,2147471152,2147470897,2147470642,2147470387,
	2147470132,2147469877,2147469622,2147469367,2147469112,2147468857,2147468602,2147468347,2147468092,2147467837,2147467582,
	2147467327,2147467072,2147466817,2147466562,2147466307,2147466052,2147465797,2147465542,2147465287,2147465032,2147464777,
	2147464522,2147464267,2147464012,2147463757,2147463502,2147463247,2147462992,2147462737,2147462482,2147462227,2147461972,
	2147461717,2147461462,2147461207,2147460952,2147460697,2147460442,2147460187,2147459932,2147459677,2147459422,2147459167,
	2147458912,2147458657,2147458402,2147458147,2147457892,2147457637,2147457382,2147457127,2147456872,2147456617,2147456362,
	2147456107,2147455852,2147455597,2147455342,2147455087,2147454832,2147454577,2147454322,2147454067,2147453812,2147453557,
	2147453302,2147453047,2147452792,2147452537,2147452282,2147452027,2147451772,2147451517,2147451262,2147451007,2147450752,
	2147450497,2147450242,2147449987,2147449732,2147449477,2147449222,2147448967,2147448712,2147448457,2147448202,2147447947,
	2147447692,2147447437,2147447182,2147446927,2147446672,2147446417,2147446162,2147445907,2147445652,2147445397,2147445142,
	2147444887,2147444632,2147444377,2147444122,2147443867,2147443612,2147443357,2147443102,2147442847,2147442592,2147442337,
	2147442082,2147441827,2147441572,2147441317,2147441062,2147440807,2147440552,2147440297,2147440042,2147439787,2147439532,
	2147439277,2147439022,2147438767,2147438512,2147438257,2147438002,2147437747,2147437492,2147437237,2147436982,2147436727,
	2147436472,2147436217,2147435962,2147435707,2147435452,2147435197,2147434942,2147434687,2147434432,2147434177,2147433922,
	2147433667,2147433412,2147433157,2147432902,2147432647,2147432392,2147432137,2147431882,2147431627,2147431372,2147431117,
	2147430862,2147430607,2147430352,2147430097,2147429842,2147429587,2147429332,2147429077,2147428822,2147428567,2147428312,
	2147428057,2147427802,2147427547,2147427292,2147427037,2147426782,2147426527,2147426272,2147426017,2147425762,2147425507,
	2147425252,2147424997,2147424742,2147424487,2147424232,2147423977,2147423722,2147423467,2147423212,2147422957,2147422702,
	2147422447,2147422192,2147421937,2147421682,2147421427,2147421172,2147420917,2147420662,2147420407,2147420152,2147419897,
	2147419642,2147419387,2147419132,2147418877,2147418622,2147418367
};
//---------------------------------------------------------------------------------------------------------------------------------
// 说明：这是方波的RAM值
//																				（数组的地址1023~0，反过来的，因为是串行写入的）
//																				（起始地址是最后一个，终止地址是第一个）
uint32_t RAM_AMP_SQUARE_WAVE[] = 
{

	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,
	0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,0x0000fffc,	
	
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,
	0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc,0x7ffffffc
};


void AD9910_RAM_Init(void)
{
	int i;
	
	uint8_t CFR1[]={0x00,0x40,0x00,0x00};
	uint8_t CFR2[]={0x01,0x40,0x08,0x20};
	uint8_t PRO[] = {0x3f, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

	// 将CFR1写入其寄存器0x00
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 将CFR2写入其寄存器0x01
	AD9910_CSN_SET(0);
	Write_8bits(0x01);
	for(i=0; i<4; i++)
		Write_8bits(CFR2[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 将RAM Profile0写入其寄存器0x0e
	AD9910_CSN_SET(0);
	Write_8bits(0x0e);
	for(i=0; i<8; i++)
		Write_8bits(PRO[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

// 设置RAM模式中的载波的频率的初始化
void AD9910_RAM_ZB_Fre_Init(void)
{
	int i;
	
	uint8_t CFR1[]={0x00,0x40,0x00,0x00}; // 开启AD9910反Sinc滤波功能
	uint8_t CFR2[]={0x00,0x41,0x08,0x20}; // 读取有效的FTW寄存器开启，FTW是写载波频率时用的
	
  // 将CFR1写入其寄存器0x00
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 将CFR2写入其寄存器0x01
	AD9910_CSN_SET(0);
	Write_8bits(0x01);														
	for(i=0; i<4; i++)
		Write_8bits(CFR2[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
	// 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

void AD9910_RAM_ZB_Fre_Set(uint32_t Freq)
{
		uint8_t FTW[]={0x00,0x00,0xa7,0xc6};
		int i;
		uint32_t Temp;  

	  Temp=(uint32_t)Freq*4.294967296; // 将输入频率转化为相应的FTW值  4.294967296=(2^32)/1000000000
		
	  FTW[3]=(uint8_t)Temp;
	  FTW[2]=(uint8_t)(Temp>>8);
		FTW[1]=(uint8_t)(Temp>>16);
	  FTW[0]=(uint8_t)(Temp>>24);
		
		AD9910_CSN_SET(0);
		Write_8bits(0x07);
		for(i=0; i<4; i++)
			Write_8bits(FTW[i]);
		AD9910_CSN_SET(1);
		Delay (10);
		
		// 更新AD9910输出
		Delay (10);
		AD9910_IUP_SET(0);
		AD9910_IUP_SET(1);
		Delay (10);
		AD9910_IUP_SET(0);
}

#if 0 
void AD9910_RAM_Fre_W(void)
{
	int i;
	uint8_t CFR1[]={0x00,0x40,0x00,0x00}; // 开启AD9910反Sinc滤波
	uint8_t CFR2[]={0x00,0x40,0x08,0x20};
	uint8_t RAM_PRO0[]={0x00,0xff,0xff,0xff,0xC0,0x00,0x00,0x00}; // 设置RAM的起始和终止地址、地址步进率
	
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
	AD9910_CSN_SET(0);
	Write_8bits(0x01);
	for(i=0; i<4; i++)
		Write_8bits(CFR2[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 将RAM的起始和终止地址、地址步进率写入相应的寄存器  0x0e
	AD9910_CSN_SET(0);
	Write_8bits(0x0e);																
	for(i=0; i<8; i++)
		Write_8bits(RAM_PRO0[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 更新一下AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
	Delay (10);
	
  // 将频率RAM的内容写入0x16寄存器
	AD9910_CSN_SET(0);								
	Write_8bits(0x16);														
	for(i=0; i<1024; i++)	
		Write_32bits(RAM_Fre[i]);
  AD9910_CSN_SET(1);
	
  // 在更新一下AD9910
  AD9910_IUP_SET(0);
  Delay (10);
  AD9910_IUP_SET(1);
  Delay (10);
  AD9910_IUP_SET(0);
  Delay (10);
}

void AD9910_RAM_AMP_W(void)
{
	int i;

	uint8_t CFR1[]={0x00,0x40,0x00,0x00}; // 开启AD9910反Sinc滤波
	uint8_t RAM_PRO0[]={0x00,0x00,0xff,0xff,0xC0,0x00,0x00,0x00}; // 设置RAM的起始和终止地址、地址步进率

// 将CFR1写入其寄存器0x00
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 将RAM的起始和终止地址、地址步进率写入相应的寄存器  0x0e
	AD9910_CSN_SET(0);
	Write_8bits(0x0e);																
	for(i=0; i<8; i++)
		Write_8bits(RAM_PRO0[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
	Delay (10);
	
  // 将幅度RAM的内容写入寄存器0x16	
	AD9910_CSN_SET(0);
	Write_8bits(0x16);
	for(i=0; i<1024; i++)	
		Write_32bits(RAM_AMP[i]);
  AD9910_CSN_SET(1);
	
  // 更新AD9910
  AD9910_IUP_SET(0);
  Delay (10);
  AD9910_IUP_SET(1);
  Delay (10);
  AD9910_IUP_SET(0);
  Delay (10);
}

void AD9910_RAM_Pha_W(void)
{
	int i;
	uint8_t CFR1[]={0x00,0x40,0x00,0x00}; // 开启AD9910反Sinc滤波
	uint8_t RAM_PRO0[]={0x00,0xff,0xff,0xff,0xC0,0x00,0x00,0x00}; // 设置RAM的起始和终止地址、地址步进率
	
  // 将CFR1写入其寄存器0x00
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0;i<4;i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 将RAM的起始和终止地址、地址步进率写入相应的寄存器  0x0e
	AD9910_CSN_SET(0);
	Write_8bits(0x0e);																
	for(i=0;i<8;i++)
		Write_8bits(RAM_PRO0[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 更新一下AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
	Delay (10);
	
  // 将频率RAM的内容写入0x16寄存器
	AD9910_CSN_SET(0);								
	Write_8bits(0x16);														
	for(i=0; i<1024; i++)
		Write_32bits(RAM_PHA[i]);
  AD9910_CSN_SET(1);
	
  // 在更新一下AD9910
  AD9910_IUP_SET(0);
  Delay (10);
  AD9910_IUP_SET(1);
  Delay (10);
  AD9910_IUP_SET(0);
  Delay (10);
}
#endif

void AD9910_WAVE_RAM_AMP_W(int mode)
{
	int i;

	uint8_t CFR1[]={0x60,0x40,0x00,0x00}; // 开启AD9910反Sinc滤波
	uint8_t RAM_PRO0[]={0x00,0x00,0x01,0xff,0xC0,0x00,0x00,0x00}; // 设置RAM的起始和终止地址、地址步进率

// 将CFR1写入其寄存器0x00
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 将RAM的起始和终止地址、地址步进率写入相应的寄存器  0x0e
	AD9910_CSN_SET(0);
	Write_8bits(0x0e);																
	for(i=0; i<8; i++)
		Write_8bits(RAM_PRO0[i]);
	AD9910_CSN_SET(1);
	Delay (10);
	
  // 更新AD9910
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
	Delay (10);
	
	AD9910_CSN_SET(0);
	Write_8bits(0x16);
	for(i=0; i<1024; i++)
	{	
		if(mode == 1)
		{
			Write_32bits(RAM_AMP[i]); // 将幅度RAM的内容写入寄存器0x16	
		}else if(mode == 2)
		{
			Write_32bits(RAM_AMP_TRIG_WAVE[i]); //将三角波的数据写入ram
		}else if(mode == 3)
		{
			Write_32bits(RAM_AMP_SQUARE_WAVE[i]); //将方波的数据写入ram
		}
	}
  AD9910_CSN_SET(1);
	
  // 更新AD9910
  AD9910_IUP_SET(0);
  Delay (10);
  AD9910_IUP_SET(1);
  Delay (10);
  AD9910_IUP_SET(0);
  Delay (10);
}

// 连续循环模式的回放-------------------------幅度
void AD9910_RAM_CON_RECIR_AMP_R(void)
{
	int i;
  // 使能RAM模式  将回放目的位设为“10” 回放幅度 （注：使能后就变成了RAM寄存器了）
	uint8_t CFR1[]={0xE0,0x40,0x00,0x00};																								
	//	从地址0回放到1023					// 连续双向斜坡模式RAM_PROx[7]=0x04
	uint8_t RAM_PRO0[]={0x00,0x00,0x01,0xff,0xc0,0x00,0x00,0x04};
	
  // 将CFR1写入其地址0x00
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);	                                                                
	Delay (10);                                                                  

	// 将RAM_RPOx写入其地址                                                                           
	AD9910_CSN_SET(0);                                                                 
	Write_8bits(0x0e);		
	for(i=0; i<8; i++)                                                                            
		Write_8bits(RAM_PRO0[i]);                                                                               
	AD9910_CSN_SET(1);	                                                                
	Delay (10); 
	
	// 更新AD9910
	AD9910_IUP_SET(0);                                                                 
	Delay (10);                                                                  
	AD9910_IUP_SET(1);                                                                 
	Delay (10);
	AD9910_IUP_SET(0);
	Delay (10);
}

#endif

#if AD9910_PARALLEL_MODE 

void AD9910_Parallel_Profile_Init(void)
{
	int i;
	
	uint8_t CFR1[]={0x00,0x40,0x00,0x00};	// 开启AD9910反Sinc滤波器					                              
	uint8_t CFR2[]={0x01,0x40,0x08,0x30};	// 使能单频Profiles调制幅度 （SYNC_CLK使能	PDCLK使能		同步时序验证禁用——这些是默认的）
	
  // 将单频模式的CFR1[]写入CFR1寄存器地址
	AD9910_CSN_SET(0);
	Write_8bits(0x00);
	for(i=0; i<4; i++)
		Write_8bits(CFR1[i]);
	AD9910_CSN_SET(1);

	Delay (10);

	// 将单频模式的CFR2[]写入CFR2寄存器地址
	AD9910_CSN_SET(0);
	Write_8bits(0x01);
	for(i=0; i<4; i++)
		Write_8bits(CFR2[i]);
	AD9910_CSN_SET(1);

	Delay (10);
	
	// 更新AD9910输出
	AD9910_IUP_SET(0);
	Delay (10);
	AD9910_IUP_SET(1);
	Delay (10);
	AD9910_IUP_SET(0);
}

void AD9910_Parallel_Profile_Set(void)
{
	
}
#endif